package com.zn.product.controller;

import com.zn.product.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/addCCar.do")
public class AddCatServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取session对象并且拿session对象中的会员编号
        Object cId = req.getSession().getAttribute("customerId");
        //如果用户编号为空
        if (cId != null) {
            //跳转到登录页面
            req.getRequestDispatcher("login.jsp").forward(req, resp);
            return ;
        }
        //将会员编号跳转为字符串类型
        String customerId = cId.toString();
        //获取商品编号
        String productId = req.getParameter("productId");
        //获取商品数量
        String number = req.getParameter("number");
        ProductService productService = new ProductService();
        boolean result = productService.addCar(customerId,productId,number);
        System.out.println("购物车添加情况:"+result);
        req.getRequestDispatcher("shopping.html").forward(req, resp);
    }
}
